package Student;

import java.util.ArrayList;
import java.util.Random;

public class RandomSelector {
    private Random random = new Random();

    public Student selectRandomStudent(String mode, StudentManager studentManager) {
        ArrayList<Student> students = studentManager.getAllStudents();
        if (students.isEmpty()) {
            return null;
        }

        switch (mode) {
            case "class":
                // 按班级随机选择
                return selectRandomStudentByClass(students);
            case "group":
                // 按小组随机选择
                return selectRandomStudentByGroup(students);
            case "student":
                // 从所有学生中随机选择
                return selectRandomStudentFromAll(students);
            default:
                return null;
        }
    }

    private Student selectRandomStudentByClass(ArrayList<Student> students) {
        // 实现按班级随机选择的逻辑
        if (students.isEmpty()) return null;
        int randomIndex = (int) (Math.random() * students.size());
        return students.get(randomIndex);
    }

    private Student selectRandomStudentByGroup(ArrayList<Student> students) {
        // 实现按小组随机选择的逻辑
        if (students.isEmpty()) return null;
        int randomIndex = (int) (Math.random() * students.size());
        return students.get(randomIndex);
    }

    private Student selectRandomStudentFromAll(ArrayList<Student> students) {
        // 实现从所有学生中随机选择的逻辑
        if (students.isEmpty()) return null;
        int randomIndex = (int) (Math.random() * students.size());
        return students.get(randomIndex);
    }


}
